package com.example.socket.websocket;

import com.example.socket.ServletRequest;

import java.io.OutputStream;

/**
 * @Classname WebSocketService
 * @Description TODO
 * @Date 2023/4/27 20:31
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class WebSocketService implements Runnable {

    private String path;

    private WebSockerHandler webSockerHandler;

    private ServletRequest request;

    private OutputStream outputStream;

    private boolean isClosed;


    @Override
    public void run() {
        while (!isClosed) {
            try {
                WebSocket webSocket=new WebSocket(null,this.outputStream,this.request);
                webSocket.setWebSockerHandler(this.webSockerHandler);
                webSocket.start();
                this.isClosed=webSocket.isCloded();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    public WebSocketService(WebSockerHandler webSockerHandler,ServletRequest servletRequest,OutputStream outputStream) {
        this.webSockerHandler = webSockerHandler;
        this.request = servletRequest;
        this.outputStream=outputStream;
        this.isClosed=false;
    }
}
